var theCharacterTimeout = 50;
var theStoryTimeout     = 5000;
var theWidgetOne        = "_";
var theWidgetTwo        = "-";
var theWidgetNone       = "";
var theLeadString       = "LATEST NEWS: &nbsp;";

var theSummaries = new Array();
var theSiteLinks = new Array();

theSummaries[0] = "The Sparkassen Chess-Meeting in Dortmund ends with GM Ponomariov in first place.";
theSiteLinks[0] = "http://www.chess.co.uk/twic/chessnews/events/sparkassen-chess-meeting-dortmund-2010";

theSummaries[1] = "Caruana at the top after Round 7 in the Biel Young GMs Tournament.";
theSiteLinks[1] = "http://www.bielchessfestival.ch/";

var theItemCount = theSummaries.length;

StartTicker();

function StartTicker(){
  theCurrentStory     = -1;
  theCurrentLength    = 0;

  if (document.getElementById){
     theAnchorObject = document.getElementById("newsAnchor");
     RunTheTicker();   	
  }
  else {
    document.write("<style>.ticki{display:none;}.ticko{border:0px; padding:0px;}</style>");
    return true;
  }
}
function RunTheTicker(){
  var myTimeout;  

  if(theCurrentLength == 0){
    theCurrentStory++;
    theCurrentStory      = theCurrentStory % theItemCount;
    theStorySummary      = theSummaries[theCurrentStory].replace(/&quot;/g,'"');
    theTargetLink        = theSiteLinks[theCurrentStory];
    theAnchorObject.href = theTargetLink;
    thePrefix            = "<span class=\"lead\">" + theLeadString + "</span>";
  }

  theAnchorObject.innerHTML = thePrefix + 
           theStorySummary.substring(0, theCurrentLength) + WhatWidget();

  if(theCurrentLength != theStorySummary.length){
    theCurrentLength++;
    myTimeout = theCharacterTimeout;
  }
  else{
    theCurrentLength = 0;
    myTimeout = theStoryTimeout;
  }

  setTimeout("RunTheTicker()", myTimeout);
}
function WhatWidget(){
  if(theCurrentLength == theStorySummary.length){
    return theWidgetNone;
  }

  if((theCurrentLength % 2) == 1){
    return theWidgetOne;
  }
  else{
    return theWidgetTwo;
  }
}